import java.util.Scanner;

/**
 * @author ShenTuZhiGang
 * @version 1.0.0
 * @email 1600337300@qq.com
 * @date 2021-008-06 19:46
 */
public class Exam2021080602 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int n = scanner.nextInt();
            bcj z = new bcj();
            for (int i = 0; i < n; i++) {
                int op = scanner.nextInt();
                if (op == 1) {
                    int a = scanner.nextInt();
                    int b = scanner.nextInt();
                    z.merge(a, b);
                } else if (op == 2) {
                    int a = scanner.nextInt();
                    int b = scanner.nextInt();
                    int c = scanner.nextInt();
                    int s = a % c;
                    int t = b % c;
                    System.out.println(z.find(s) == z.find(t) ? "YES" : "NO");
                }
            }
        }
    }

    static class bcj {
        int[] t = new int[20000];

        public int find(int x) {
            if (t[x] == 0) {
                return x;
            }
            return find(t[x]);
        }

        public void merge(int a, int b) {
            int q = find(a);
            int p = find(b);
            if (q != p) {
                t[q] = p;
            }
        }
    }
}
